using System;
using EventBehaviorTree;
using UnityEngine;

namespace BuffSystem
{
    [Serializable]
    public class Register : CarrierComponent, IAction
    {
        protected PropertyModifier _modifier;
        protected TagSystem _tagSystem;
        public Register(string occupantName) : base(occupantName) { }
        public void SetOccupantType(OccupantType occupantType) { _occupantType = occupantType; }
        public void SetOccupant(PropertyModifier modifier) { _modifier = modifier; }
        public void SetOccupant(TagSystem tagObject) { _tagSystem = tagObject; }
        public override void RegisterPrepare(Buff buff, BuffManager owner, BuffManager target)
        {
            base.RegisterPrepare(buff, owner, target);
            if (_occupantType == OccupantType.Tag) { _tagSystem._buffKey = _buff._key.ToString(); }
        }
        public void Action()
        {
            //Debug.Log(GetType() + "/" + _occupantType + "/" + _occupantKey);
            switch (_occupantType)
            {
                case OccupantType.Buff:
                    //Debug.Log(_occupantName);
                    AssetsManager.AssetsManagerInstance.DeserializeBuff(_occupantName).RegisterBuff(_owner, _target);
                    break;
                case OccupantType.PropertyModifier:
                    _target.Register(_occupantKey.ToString(), _modifier);
                    break;
                case OccupantType.Tag:
                    _target.Register(_occupantKey.ToString(), _tagSystem);
                    break;
                default:
                    break;
            }
        }
    }
}